<?php

namespace app\common\model;

/**
 * 活动模型
 * Class Activity
 * @package app\common\model
 */
class Activity extends BaseModel
{
    protected $name = 'Activity';
    protected $append = [];

    /**
     * 关联活动封面图
     * @return \think\model\relation\HasOne
     */
    public function image()
    {
        return $this->hasOne('uploadFile', 'file_id', 'image_id');
    }

    /**
     * 关联活动分队
     * @return \think\model\relation\BelongsTo
     */
    public function team()
    {
        $module = self::getCalledModule() ?: 'common';
        return $this->BelongsTo("app\\{$module}\\model\\Team");
    }

    /**
     * 用户
     * @return \think\model\relation\HasOne
     */
    public function user()
    {
        return $this->hasOne('user', 'user_id', 'examine_uid');
    }

    /**
     * 活动详情
     * @param $Activity_id
     * @return null|static
     * @throws \think\exception\DbException
     */
    public static function detail($Activity_id)
    {
        return self::get($Activity_id, ['image', 'team']);
    }

}
